package com.etc.service.impl;

import java.util.List;

import com.etc.dao.OrderDetailDao;
import com.etc.dao.impl.OrderDetailDaoImpl;
import com.etc.entity.Games;
import com.etc.entity.OrderDetail;
import com.etc.service.OrderDetailService;

public class OrderDetailServiceImpl implements OrderDetailService{
	private OrderDetailDao orderDetailDao = new OrderDetailDaoImpl();
	/**
	 * 创建一条订单详情orderDetail，前端传来订单号为0表示存在购物车中，未进行提交订单以及支付等后续操作
	 */
	@Override
	public boolean insertOrderDetail(OrderDetail orderDetail) {
		return orderDetailDao.insert(orderDetail) > 0;
	}
	/**
	 * 通过用户编号和未提交订单号为0，查询用户先前加入购物车但未提交订单的游戏的订单详情，包括游戏信息，用于显示购物车
	 */
	@Override
	public List<Games> findGamesByCustomerId(Integer customerId, String orderNo, Integer gamesId) {
		return orderDetailDao.findByCustomerId(customerId, orderNo, gamesId);
	}
	/**
	 * 根据支付状态，游戏编号和用户编号查询已支付的订单
	 */
	@Override
	public OrderDetail findInfoByStatusAndGamesIdAndCustomerId(Integer status, Integer gamesId, Integer customerId) {
		return orderDetailDao.findByStatusAndGamesIdAndCustomerId(status, gamesId, customerId);
	}
	/**
	 * 根据订单号，游戏编号，用户编号删除对应的订单详情
	 */
	@Override
	public boolean deleteOrderDetailByOrderNoAndGamesIdAndCustomerId(String orderNo, Integer gamesId, Integer customerId) {
		return orderDetailDao.deleteByOrderNoAndGamesIdAndCustomerId(orderNo, gamesId, customerId) > 0;
	}

}
